// import router from '@/router/index'
import axios from 'axios';
import $router from "../router/index";
const instance = axios.create({
    baseURL: window.axiosurl,
    headers: { 'Content-type': 'application/json' }
})

// //请求
instance.interceptors.request.use((config) => {
    config.headers.visitorId=localStorage.getItem("visitorId")
    return config
}, (err) => {
    return Promise.reject(err.request)
})

// //响应
instance.interceptors.response.use((response) => {
   
    return response
}, (err)=> {
    console.log(err.response.data.statusCode);
   let errCode=err.response.data.statusCode
     if (errCode==401) {
         localStorage.clear()
        $router.push({path:"/login"}) 
     }
    return Promise.reject(err.response)

})



async function Get(parame) {
    const { url, data ,headers} = parame;
        return await instance.get(url, {
            params: data,
            headers
        })
}

async function Post(parame) {
    const { url, data ,headers} = parame;
        return await instance.post(url, data,{headers})
}


export { Get, Post }